]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
unlockDialog: Show media notifications on lock screen
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 26 Feb 2017 13:55:48 +0000 (14:55 +0100)
committerMarge Bot <marge-bot@gnome.org>
Fri, 8 Aug 2025 21:42:17 +0000 (21:42 +0000)
While we have included a built-in media section in the calendar for
a while, it is currently only available when the session is unlocked.
The ability to quickly pause or resume media playback directly from
the lock screen is quite handy though, so start showing them alongside
the existing screen shield notifications.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/488
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3306>

js/ui/unlockDialog.js

index 77e80571ee5a68965dbcf233b85138c2453d4432..fae4d0787dc65baa0678a426298e4ffd3763b21e 100644 (file)
@@ -16,6 +16,8 @@ import * as MessageTray from './messageTray.js';
 import * as SwipeTracker from './swipeTracker.js';
 import {formatDateWithCFormatString} from '../misc/dateUtils.js';
 import * as AuthPrompt from '../gdm/authPrompt.js';
+import {MprisSource} from './mpris.js';
+import {MediaMessage} from './messageList.js';
 
 // The timeout before going back automatically to the lock screen (in seconds)
 const IDLE_TIMEOUT = 2 * 60;
@@ -49,6 +51,16 @@ const NotificationsBox = GObject.registerClass({
         });
         this.add_child(this._scrollView);
 
+        this._players = new Map();
+        this._mediaSource = new MprisSource();
+        this._mediaSource.connectObject(
+            'player-added', (o, player) => this._addPlayer(player),
+            'player-removed', (o, player) => this._removePlayer(player),
+            this);
+        this._mediaSource.players.forEach(player => {
+            this._addPlayer(player);
+        });
+
         this._settings = new Gio.Settings({
             schema_id: 'org.gnome.desktop.notifications',
         });
@@ -69,6 +81,9 @@ const NotificationsBox = GObject.registerClass({
         let items = this._sources.entries();
         for (let [source, obj] of items)
             this._removeSource(source, obj);
+
+        for (const player of this._players.keys())
+            this._removePlayer(player);
     }
 
     _updateVisibility() {
@@ -202,6 +217,20 @@ const NotificationsBox = GObject.registerClass({
             this.emit('wake-up-screen');
     }
 
+    _addPlayer(player) {
+        const message = new MediaMessage(player);
+        this._players.set(player, message);
+        this._notificationBox.insert_child_at_index(message, 0);
+        this._updateVisibility();
+    }
+
+    _removePlayer(player) {
+        const message = this._players.get(player);
+        this._players.delete(player);
+        message.destroy();
+        this._updateVisibility();
+    }
+
     _sourceAdded(tray, source, initial) {
         let obj = {
             visible: source.policy.showInLockScreen,
@@ -217,7 +246,7 @@ const NotificationsBox = GObject.registerClass({
             x_expand: true,
         });
         this._showSource(source, obj, obj.sourceBox);
-        this._notificationBox.add_child(obj.sourceBox);
+        this._notificationBox.insert_child_at_index(obj.sourceBox, this._players.size);
 
         source.connectObject(
             'notify::count', () => this._countChanged(source, obj),